package com.sophie.service.impl;

import com.sophie.dao.IFollowDAO;
import com.sophie.dao.impl.FollowDAOImpl;
import com.sophie.entity.Follow;
import com.sophie.service.IFollowService;
import com.sophie.util.ResultVO;
import org.apache.poi.ss.formula.functions.T;

import java.util.List;

/**
 * @Author: Rowena
 * @CreateTime: 2024-09-11 09:00:05
 * @Version: 1.0
 */

public class FollowServiceImpl implements IFollowService {
    IFollowDAO followDAO = new FollowDAOImpl();
    @Override
    public ResultVO addFollow(Follow follow) {
        int i = followDAO.addFollow(follow);
        if (i>0){
            return ResultVO.ok("关注成功!");
        }
        return ResultVO.ok("关注失败!");
    }

    @Override
    public ResultVO getAllFollowId(Integer id) {
        List<T> allFollowId = followDAO.selectFollowById(id);
        if (!allFollowId.isEmpty()){
            return ResultVO.ok("所有关注对象id获取成功!").setData(allFollowId);
        }
        return ResultVO.fail("所有关注对象id获取失败!");
    }

    @Override
    public ResultVO checkFollow(Integer id,Integer userid) {
        int i = followDAO.checkFollow(id,userid);
        if (i>0){
            return ResultVO.ok("该用户已关注!");
        }
        return ResultVO.fail("该用户未关注!");
    }

    @Override
    public ResultVO countFans(Integer id) {
        long l = followDAO.countFans(id);
        if (l>0){
            return ResultVO.ok("粉丝数量获取成功!").setData(l);
        }
        return ResultVO.fail("粉丝数量获取失败!");
    }

    @Override
    public ResultVO countFollows(Integer id) {
        long l = followDAO.countFollows(id);
        if (l>0){
            return ResultVO.ok("关注数量获取成功!").setData(l);
        }
        return ResultVO.fail("关注数量获取失败!");
    }
}
